//
//  AddDeviceS1Controller.m
//  O2Cat
//
//  Created by xiabin on 15/12/17.
//  Copyright © 2015年 QiDao.Purifier. All rights reserved.
//

#import "AddDeviceS1EnterController.h"
#import "SettingPageController.h"
#import "AddDeviceS2InfoController.h"

@interface AddDeviceS1EnterController () {
    
}

@property (nonatomic,strong) UIButton* addDeviceBtn;
@property (nonatomic,strong) UILabel* addDeviceLabel;
@property (nonatomic,strong) UIImageView* logoImage;

@end

@implementation AddDeviceS1EnterController

- (void)viewDidLoad {

    [super viewDidLoad];
     self.view.backgroundColor = QGPageBG;
    [self.view addSubview:self.logoImage];
    //[self.view addSubview:self.addDeviceLabel];
    [self.view addSubview:self.addDeviceBtn];
    
    [self layoutSubViews];
    // Do any additional setup after loading the view.
}

- (void) viewWillAppear:(BOOL)animated {
    [self setupNavStyle];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void) setupNavStyle {
    UIView *statusBarView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_SIZE_WIDTH, 20)];
    statusBarView.backgroundColor=QGNavBG;
    [self.view addSubview:statusBarView];
    self.navigationController.navigationBar.backgroundColor = QGNavBG;
    self.navigationController.navigationBar.barTintColor = QGNavBG;
    self.navigationItem.title = @"奇道空气净化";

    
    UIButton* settingBtn = [Utils NavButtonStyleNormalBLeft:YES NormalImg:@"setting" AndHightLight:@"setting"];
    [settingBtn addTarget:self action:@selector(showSettingPage) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:settingBtn];
}

-(void) showSettingPage {
    SettingPageController* settingPage = [SettingPageController new];
    [self.navigationController pushViewController:settingPage animated:YES];
}

-(void) onAddDevice {
    AddDeviceS2InfoController* step2 = [[AddDeviceS2InfoController alloc] init];
    [self.navigationController pushViewController:step2 animated:YES];
}

-(void) layoutSubViews {
    //顶部排布
    __weak __typeof(&*self)weakSelf = self;
    
    [self.addDeviceBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.view.mas_top).offset(SCREEN_SIZE_HEIGHT/4);
        make.centerX.mas_equalTo(weakSelf.view.mas_centerX).offset(0);
        make.height.mas_equalTo(SCREEN_SIZE_WIDTH/2);
        make.width.mas_equalTo(SCREEN_SIZE_WIDTH/2);
    }];
    
    /*[self.addDeviceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.addDeviceBtn.mas_bottom).offset(20);
        make.centerX.mas_equalTo(weakSelf.addDeviceBtn.mas_centerX).offset(0);
        //make.height.mas_equalTo(SCREEN_SIZE_WIDTH/3);
        //make.width.mas_equalTo(SCREEN_SIZE_WIDTH/3);
    }];*/
    
    [self.logoImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(weakSelf.view.mas_bottom).offset(-30);
        make.centerX.mas_equalTo(weakSelf.view.mas_centerX).offset(0);
    }];
}

-(UIButton*) addDeviceBtn {
    if (_addDeviceBtn == nil) {
        _addDeviceBtn = [[UIButton alloc] init];
        //[_addDeviceBtn setBackgroundImage:[UIImage imageNamed:@"add"] forState:UIControlStateNormal];
        _addDeviceBtn.backgroundColor = QGNavBG;
        [_addDeviceBtn setTitle:@"点击查找新设备" forState:UIControlStateNormal];
        [_addDeviceBtn setTitleColor:QGTextWhite forState:UIControlStateNormal];
        [_addDeviceBtn setTitleColor:QGTextGrayL1 forState:UIControlStateHighlighted];
        _addDeviceBtn.layer.cornerRadius = SCREEN_SIZE_WIDTH/4;
        [_addDeviceBtn addTarget:self action:@selector(onAddDevice) forControlEvents:UIControlEventTouchUpInside];
    }
    return _addDeviceBtn;
}


-(UILabel*) addDeviceLabel {
    if (_addDeviceLabel == nil) {
        _addDeviceLabel = [[UILabel alloc] init];
        _addDeviceLabel.text = @"点击添加新设备";
        _addDeviceLabel.textColor = QGTextGrayL2;
        _addDeviceLabel.font = [UIFont systemFontOfSize:[Utils phoneFontL4]];
        [_addDeviceLabel sizeToFit];
    }
    return _addDeviceLabel;
}

-(UIImageView*) logoImage {
    if (_logoImage == nil) {
        _logoImage = [[UIImageView alloc] init];
        _logoImage.image = [UIImage imageNamed:@"deslabel"];
    }
    return _logoImage;
}

@end
